package crm.view.Admin;

//   功能已实现

import crm.dao.impl.CustomerSqlSeverImpl;
import crm.entity.Customer;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/*删除用户 */
public class deleteCustomer implements ActionListener {
    JFrame frame = null;
    JLabel name = null;
    JTextField NameField = null;
    JLabel label = null;

    JButton btn1 = null;


    public static void main(String[] args) {
        new deleteCustomer();
    }

    public deleteCustomer() {
        init();
        frame.setBounds(680, 300, 583, 369);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLayout(null);
        frame.setVisible(true);
    }

    public void init() {
        frame = new JFrame("客户基本信息");
        name = new JLabel("输入用户姓名:");
        NameField = new JTextField("");
        label = new JLabel("删除用户");
        btn1 = new JButton("删除");

        Font font1 = new Font("宋体", Font.BOLD, 50);
        label.setFont(font1);

        Font font2 = new Font("宋体", Font.BOLD, 20);
        btn1.setFont(font2);
        name.setFont(font2);
        NameField.setFont(font2);

        frame.add(btn1);
        frame.add(name);
        frame.add(NameField);
        frame.add(label);

        label.setBounds(170, 20, 250, 50);
        name.setBounds(80, 100, 150, 50);
        NameField.setBounds(230, 100, 200, 40);
        btn1.setBounds(220, 150, 100, 40);

        btn1.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        CustomerSqlSeverImpl dao = new CustomerSqlSeverImpl();
        Customer customer = new Customer();

        if ("删除".equals(e.getActionCommand())) {
            String name = NameField.getText();
            if ("".equals(name)) {
                JOptionPane.showMessageDialog(null, "请输入用户姓名！");
            } else {
                customer.setCustomer_name(name);
                int i = dao.deleteByName(customer);
                System.out.println(i);
                if (i > 0) {
                    JOptionPane.showMessageDialog(null, "删除成功！");
                }else{
                    JOptionPane.showMessageDialog(null, "表中无此人！");

                }
            }

        }

    }
}
